package BeheerFysiotherapeuten.View;

import BeheerFysiotherapeuten.Model.Praktijk;
import BeheerFysiotherapeuten.Model.PraktijkLijst;

import java.awt.Dimension;
import java.awt.event.ActionListener;

import java.util.Observable;
import java.util.Observer;


public class PraktijkOverzicht extends javax.swing.JPanel implements Observer {
	private Object[][] inhoud;
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JButton jButton4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable jTable1;

	

	public PraktijkOverzicht() {

	

		initComponents();

	}

	public void setListener(ActionListener listener) {

		jButton1.addActionListener(listener);
		jButton2.addActionListener(listener);
		jButton3.addActionListener(listener);
		jButton4.addActionListener(listener);


	}

	public Object[][] getInhoud() {
		return inhoud;

	}

	public void setInhoud(Object[][] inhoud) {
		this.inhoud = inhoud;

		jTable1.setModel(new javax.swing.table.DefaultTableModel(inhoud,
				new String[] { "Praktijknaam", "Adres", "Postcode",
						"telefoonNr" }));

	}

	private void initComponents() {
		jButton1 = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();
		jButton4 = new javax.swing.JButton();

		jButton1.setActionCommand("Nieuw");

		jButton2.setActionCommand("Wijzig");

		jButton3.setActionCommand("Verwijder");
		jButton4.setActionCommand("Rooster");

		jScrollPane1 = new javax.swing.JScrollPane();

		
		jTable1 = new javax.swing.JTable(){
			public boolean isCellEditable(int row, int coll){
				return false;
			}
		};
		jTable1.getTableHeader().setReorderingAllowed(false);

		

		jTable1.setModel(new javax.swing.table.DefaultTableModel(inhoud,
				new String[] { "Praktijknaam", "Adres", "Postcode",
						"telefoonNr" }

		));
		jScrollPane1.setViewportView(jTable1);
		jTable1.setPreferredScrollableViewportSize(new Dimension(700, 600));
		jTable1.setFillsViewportHeight(true);
		jButton1.setText("toevoegen");

		jButton2.setText("Wijzigen");

		jButton3.setText("Verwijderen");
		
		jButton4.setText("Rooster");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														jButton4,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														jButton3,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														jButton2,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														jButton1,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addContainerGap(563, Short.MAX_VALUE))
				.addGroup(
						layout.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(
										layout.createSequentialGroup()
												.addGap(0, 105, Short.MAX_VALUE)
												.addComponent(
														jScrollPane1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addGap(0, 105, Short.MAX_VALUE))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(jButton1)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jButton2)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jButton3)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jButton4)
								.addContainerGap(335, Short.MAX_VALUE))
				.addGroup(
						layout.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(
										layout.createSequentialGroup()
												.addGap(0, 0, Short.MAX_VALUE)
												.addComponent(
														jScrollPane1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addGap(0, 0, Short.MAX_VALUE))));
	}

	@Override
	public void update(Observable o, Object arg) {
		PraktijkLijst lijst = (PraktijkLijst) o;

		int i = 0;

		Object[][] inhoud = new Object[lijst.lengtePraktijken()][4];
		for (Praktijk item : lijst.stuurLijst()) {

			inhoud[i][0] = (Object) item.getNaam();
			inhoud[i][1] = (Object) item.getAdres();
			inhoud[i][2] = (Object) item.getPostcode();
			inhoud[i][3] = (Object) item.getTelNr();

			i++;

		}
		jTable1.setModel(new javax.swing.table.DefaultTableModel(inhoud,
				new String[] { "Praktijknaam", "Adres", "Postcode",
						"telefoonNr" }));

	}

	public int getSelected() {
		
		return jTable1.getSelectedRow();

	}

}
